package com.wlf.server.common.config;

import cloud.tianai.captcha.common.constant.CaptchaTypeConstant;
import cloud.tianai.captcha.resource.ResourceStore;
import cloud.tianai.captcha.resource.common.model.dto.Resource;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;


/**
 * 功能描述: 验证码资源加载
 *
 * @author wlf 2023/9/16 21:08
 */
@Component
@RequiredArgsConstructor
public class CaptchaResourceStore {

    private final ResourceStore resourceStore;


    public void init() {
        for (int i = 1; i < 13; i++) {
            resourceStore.addResource(CaptchaTypeConstant.SLIDER, new Resource("classpath", StrUtil.format("captcha-images/{}.jpg", i), "default"));
            resourceStore.addResource(CaptchaTypeConstant.ROTATE, new Resource("classpath", StrUtil.format("captcha-images/{}.jpg", i), "default"));
            resourceStore.addResource(CaptchaTypeConstant.CONCAT, new Resource("classpath", StrUtil.format("captcha-images/{}.jpg", i), "default"));
            resourceStore.addResource(CaptchaTypeConstant.WORD_IMAGE_CLICK, new Resource("classpath", StrUtil.format("captcha-images/{}.jpg", i), "default"));
        }
    }

}
